<{include file="public/member_header" /}>
<script type="text/javascript">
 // 解码  
	function decode( str ){
		var div = document.createElement('div');
		div.innerHTML = str;
		return div.innerHTML;
	}
    $(function() {
        var uploader = new plupload.Uploader({
            drop_element : 'container',
            runtimes: 'html5,flash,silverlight,html4',
            browse_button: 'uploadstart',
            container: document.getElementById('container'),
            url : '<{:url('upload')}>',
            flash_swf_url : '__STATIC__/plupload/js/Moxie.swf',
            silverlight_xap_url : '__STATIC__/plupload/js/Moxie.xap',
            filters: {
                max_file_size: '5mb',
                mime_types: [{
                    title: "文档上传"
                    ,extensions: "docx"//"doc,docx,txt"
                }]
            },
            multi_selection : false,
            init : {
                PostInit: function() {},
                FilesAdded: function(up, files) {
                    uploader.start();
                },
                BeforeUpload: function(up, files) {
                    //console.log(up);
                    //console.log(files);
                },
                UploadProgress: function(up, file) {
                    $(".upload-scale").html("已上传：" + file.percent + "%");
                    $(".progress-bar").css("width", file.percent + "%");
                },
                FileUploaded: function(up, file, info) {
                    uploader.refresh();
                    var jsonData = info;
                    var jsonObj=JSON.parse(jsonData.response);
                    // console.log(file);
                    // console.log(info);
                    //console.log(jsonObj)
                    if(jsonObj==1){
                        $('#look').hide();
                        $('#content').val('');
                        alert("文件上传失败");
                        return false;
                    }else if(jsonObj==2){
                        $('#look').hide();
                        $('#content').val('');
                        alert("内容获取失败");
                        return false;
                    }else{
                        ue.setContent(jsonObj.html);
                        $('#title').val(decode( jsonObj.title ));
                        $('#lookview').show(); //暂时隐藏
                        $('#lookview2').show(); //暂时隐藏
                    }
                },
                Error: function(up, err) {
                    //console.log(up);
                    //console.log(err);
                    if(err.code==-600){
                        alert("您所上传的文件请小于5M");
                        return false;
                    }
                    if(err.code==-601){
                        alert("您所上传的文件类型有误");
                        return false;
                    }
                }
            }
        });
        uploader.init();
    });
    function submitbut() {
        var title=$('#title').val();
        var beizhu=$('#beizhu').val();
       if(title==""){
           alert("文字标题不能为空");
           return false;
       }
        $('#MyForm').submit();
    }
</script>
<div class="am-cf admin-main">
  <!-- sidebar start -->
  <{include file="public/member_main" /}>
  <!-- sidebar end -->
  <div class="admin-content content-article">
    <div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf am-btn-group">
 		   <a href="<{:url('article/index')}>" class="am-btn am-btn-default am-btn-sm">发布媒体</a>
		  <a href="<{:url('wearticle/index')}>" class="am-btn am-btn-primary am-btn-sm">发布自媒体</a> 
		  </div>
      </div>
      <hr>
    </div>
    <div class="page-content">
      <div class="page-content-area" style="margin-left: 3%;" >
      <form id="formlook" method="post" <{if condition="$AgencySiteInfo.Domain eq '-1'"}>action="/index/welook"<{else}>action="<{:url("welook")}>"<{/if}> target="_blank">
      <input type="hidden" name="opentitle" id="opentitle">
      <textarea style="display:none;" name="opencontent" id="opencontent"></textarea>
      <input type="hidden" name="openbeizhu" id="openbeizhu">
      </form>
      <form class="am-form" id="MyForm" method="post" action="<{:url("wemedia")}> ">
        <div class="am-u-sm-12 am-u-md-1 am-md-text-right">上 传：</div>
        <div style="display: block; height: 32px; line-height: 32px;"> <span class="am-btn am-btn-primary am-btn-md" id="uploadstart">上传文档，支持DOCX格式，office2007,2010,2013,2016</span> <span style="color: red; padding-left: 10px;">请上传5M以内的文档</span>
          <input type="file" name="WordFile" id="container" style="display: none;">
          <div style="margin-left:10px;float: left; height: 32px; line-height: 32px;">
            <div class="progress-bar" style="height: 18px; margin-top: 6px;"></div>
          </div>
          <div style=" margin-left:10px;float: left; height: 32px; line-height: 32px;" role="progressbar">
            <div class="upload-scale"></div>
          </div>
        </div>

		<div class="am-g am-margin-top">
			<div class="am-u-sm-12 am-u-md-1 am-md-text-right" style="color: red;height: 40px;line-height: 40px;">视频：</div>
			<div class="am-u-sm-12 am-u-md-11">
				<div id="container" style="position: relative;">
				<div class="lawyer_vido1" style="overflow:hidden;">
					<div id="uploader" class="videoMain">
						<!--用来存放文件信息-->
						<div id="thelist" class="uploader-list"></div>
						<div id="picker" class="btns" style="float: left;margin-right: 20px;">选择视频</div>
						<div class="btns uploadBtn" id="ctlBtn" style="float: left; height: 40px;">开始上传</div>
					</div>
				</div>
			</div>
			<span style="color: red; padding-left: 10px;">视频文件支持 MP4,FLV格式</span>
		</div>
	   </div>
        <div class="am-g am-margin-top">
          <div class="am-u-sm-12 am-u-md-1 am-md-text-right">标 题：</div>
          <div class="am-u-sm-12 am-u-md-11">
            <input id="title" type="text" name="title" value="<{$title}>" autocomplete="off" placeholder="建议25字内,不要出现特殊字符,否则容易乱码" style="width:350px;">
            <span class="title_notice">建议与来源标题一致，避免产生纠纷（不保证一定使用来源标题或当前标题）</span> </div>
        </div>
        <div class="am-g am-margin-top" style="margin-top: 30px;">
          <div class="am-u-sm-12 am-u-md-1 am-md-text-right">内 容：</div>
          <textarea id="editorValue" name="editorValue"  class="am-u-md-7"><{$editorValue}></textarea>
        </div>
        <div class="am-g am-margin-top">
          <div class="am-u-sm-12 am-u-md-1 am-md-text-right" style="margin-top: 20px;">备 注：</div>
          <div class="am-u-sm-12 am-u-md-11" style="margin-top: 20px;">
            <input type="text" name="beizhu"  value="<{$beizhu}>" id="beizhu" autocomplete="off" style="width: 250px">
          </div>
        </div>
        <div class="am-g">
          <div class="am-u-sm-12 am-u-md-1 am-md-text-right" style="margin-top: 20px;">客 户：</div>
          <div class="am-u-sm-12 am-u-md-11" style="margin-top: 20px;">
            <input type="text" name="article_customer"  value="<{$article_customer}>" id="article_customer" autocomplete="off" style="width: 250px" >
          </div>
        </div>
        <div class="am-g am-margin-top">
          <div class="am-u-sm-12 am-u-md-1 am-md-text-right">定 时：</div>
          <div class="am-u-sm-12 am-u-md-11">
            <input type="text" value="<{$starttime}>" name="starttime" data-am-datepicker  id="starttime" autocomplete="off" style="width: 250px" >
          </div>
        </div>
        <div style="margin: 20px 0 20px 30px; "> 余 额 <{$MemberBalanceCount}> 元 [第一步：填写标题、内容；点击下一步；选择要发布的自媒体，提交订单，发布成功。 </div>
        <div style="margin: 20px 0px 60px 30px; display:block" >
          <button id="preview" type="button" class="am-btn am-btn-primary" onClick="look();">预览</button>
          <button type="button" class="am-btn am-btn-warning" onClick="submitbut();">下一步 选择媒体</button>
        </div>
        <div class="zhuyi">
          <input type="hidden" name="TempArticleID" value="<{:md5(mt_rand(100000,999999).'_'.time().'_'.mt_rand(100000,999999))}>">
          <div style="font-size: 16px; font-weight: bold;">发稿注意事项</div>
			 <{$MainConfig.WebSitemmedia}>
		  </div>
      </form>
    </div>
  </div>
</div>
<{include file="public/member_footer" /}>
<link rel="stylesheet" type="text/css" href="/static/member/webuploader/webuploader.css">
<script type="text/javascript" src="/static/member/webuploader/webuploader.js"></script>
<script type="text/javascript">
    //UEditor placeholder
    UE.Editor.prototype.placeholder = function (justPlainText) {
        var _editor = this;
        _editor.addListener("focus", function () {
            var localHtml = _editor.getPlainTxt();
            if ($.trim(localHtml) === $.trim(justPlainText)) {
                _editor.setContent(" ");
            }
        });
        _editor.addListener("blur", function () {
            var localHtml = _editor.getContent();
            if (!localHtml) {
                _editor.setContent(justPlainText);
            }
        });
        _editor.ready(function () {
            _editor.fireEvent("blur");
        });
    };
     var ue = new UE.ui.Editor({initialFrameHeight:400 });
        ue.render("editorValue")
        ue.ready(function() {
            ue.placeholder("特别注意:1.小红书字数限制为1000字内，多了发不出  2.百家新手号一般一天只可发布一篇文章，已在百家号发过的文章无法再发布别的百家号");
        });
    function look() {
        var title=$('#title').val();
        $('#opentitle').val(title);
        var html = ue.getContent();
        $('#opencontent').val(html);
        $('#openbeizhu').val($('#beizhu').val());
        $('#formlook').submit();
    }
	
/*视频上传*/
// 初始化Web Uploader
var uploader = WebUploader.create({
    // swf文件路径
    swf:  '/static/member/webuploader/Uploader.swf',
    // 文件接收服务端。
    server: "/member.php/wearticle/ajax_vido",
    // 选择文件的按钮。可选。
    // 内部根据当前运行是创建，可能是input元素，也可能是flash.
    pick: {
       id: "#picker",
       multiple: false,
    },
	formData: {
       folder:'files',  //自定义参数
    },
	accept: {
       title: 'Images',
       extensions: 'mp4,flv',
     },
    // 验证文件总数量, 超出则不允许加入队列
    fileNumLimit: 1, 
    // 开启分片上传
    chunked: true,  
    // 如果要分片，分多大一片？ 默认大小为5M
    chunkSize: 2*1024*1024,
    // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
    resize: false,
    duplicate: true,
});
jQuery(function($){
    // 点击长传
    $("#ctlBtn").on('click', function(){
        uploader.upload();
    })
    // 显示用户选择
    uploader.on('fileQueued', function(file) {
        $("#thelist").append( '<div id="' + file.id + '" class="item">' +
            '<h4 class="info">' + file.name + '</h4>' +
            '<p class="state">等待上传...</p>' +
        '</div>' );
    });
    // 文件上传进度
    // 文件上传中，Web Uploader会对外派送uploadProgress事件，其中包含文件对象和该文件当前上传进度。
    uploader.on('uploadProgress', function(file, percentage) {
        var $li = $('#'+file.id ),
            $percent = $li.find('.progress .progress-bar');

        // 避免重复创建
        if (!$percent.length) {
            $percent = $('<div class="progress progress-striped active">' +
              '<div class="progress-bar" role="progressbar" style="width: 0%">' +
              '</div>' +
            '</div>').appendTo($li).find('.progress-bar');
        }
        $li.find('p.state').text('上传中');
        $percent.css( 'width', percentage * 100 + '%' );
    });
    // 文件成功、失败处理
    // 成功则派送uploadSuccess事件
    uploader.on('uploadSuccess', function(file, data) {
		//console.log(data);
        $('#'+file.id).find('p.state').text('已上传');
       // $("input[name=lawyer_vido]").val(data.oldName);
		alert("视频文件已上传成功");
		var html = ""
        html += '<p><video src="http://www.zxal.cn'+data.filePath+'" controls="controls"  style="display: block;margin:auto;">'+'</video></p><br/>';
		UE.getEditor("editorValue").setContent(html,true);
		//UE.getEditor("editorValue");
    });
    
    // 文件上传失败会派送uploadError事件
    uploader.on('uploadError', function(file) {
        $( '#'+file.id ).find('p.state').text('上传出错');
    });
    // 管成功或者失败，在文件上传完后都会触发uploadComplete事件
    uploader.on('uploadComplete', function(file) {
        $( '#'+file.id ).find('.progress').fadeOut();
    });
});
</script>
</body>
</html>
